import {TABKEY} from '../config.js'
import {GET_FILTER_DATA, HEADER_TAB,CHANGE_FILTER} from "../actions/actionTypes";

let tabs = {}
tabs[TABKEY.cate]={
  key: TABKEY.cate,
  text:'全部分类',
  obj:{}
}
tabs[TABKEY.type]={
  key: TABKEY.type,
  text:'综合排序',
  obj:{}
}
tabs[TABKEY.filter]={
  key: TABKEY.filter,
  text:'筛选',
  obj:{}
}
const initState = {
  tabs: tabs,
  activekey: TABKEY.cate,
  filterData:{},
  closePanel: true
}
const changTab=(state,action)=>{
  return{...state,activekey: action.obj.activekey,closePanel:action.obj.closePanel }
}
const getFileterData=(state,action)=>{
  return{...state,filterData: action.obj.data}
}
const changeFilter=(state,action)=>{
  let _tabs = JSON.parse(JSON.stringify(state.tabs))
  _tabs[action.obj.key]={
    key:action.obj.key,
    text:action.obj.item.name,
    obj:action.obj.item
  };
  return {...state,tabs:_tabs}
}
const headerReducer = (state = initState, action) => {
  switch (action.type) {
    case HEADER_TAB:
      return changTab(state,action)
    case GET_FILTER_DATA:
      return getFileterData(state,action)
    case CHANGE_FILTER:
      return changeFilter(state,action)
    default :
      return state;
  }
}
export default headerReducer